
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
  <base href="/">
  <meta charset="utf-8">
  <title>注册</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="keywords" content="fly,layui,前端社区">
  <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区，致力于为web开发提供强劲动力">
  <link rel="stylesheet" href="res/layui/css/layui.css">
  <link rel="stylesheet" href="res/css/global.css">
</head>
<body>

<div class="fly-header layui-bg-black">
  <div class="layui-container">
    <a class="fly-logo" href="/">
      <img th:src="${index[0].blogLogo}" alt="layui" width="200" height="40">
    </a>

    
    <ul class="layui-nav fly-nav-user">
      <!-- 未登入的状态 -->
      <shiro:guest>
      <li class="layui-nav-item">
        <a class="iconfont icon-touxiang layui-hide-xs" href="user"></a>
      </li>
      <li class="layui-nav-item">
        <a href="user">登入</a>
      </li>
      <li class="layui-nav-item">
        <a href="user/userregist">注册</a>
      </li>
      </shiro:guest>
    </ul>
  </div>
</div>

<div class="layui-container fly-marginTop">
  <div class="fly-panel fly-panel-user" pad20>
    <div class="layui-tab layui-tab-brief" lay-filter="user">
      <ul class="layui-tab-title">
        <li><a href="user">登入</a></li>
        <li class="layui-this">注册</li>
      </ul>
      <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
        <div class="layui-tab-item layui-show">
          <div class="layui-form layui-form-pane">
            <div class="layui-form">
              <div class="layui-form-item">
                <label for="LAY-user-login-username" class="layui-form-label">用户名</label>
                <div class="layui-input-inline">
                  <input type="text" id="LAY-user-login-username" name="username"  placeholder="用户名" required  autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">将会成为您唯一的登入名</div>
              </div>
              <div class="layui-form-item">
                <label for="LAY-user-login-nickname" class="layui-form-label">昵称</label>
                <div class="layui-input-inline">
                  <input type="text" id="LAY-user-login-nickname" name="nickname" required lay-verify="required" placeholder="昵称" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label for="LAY-user-login-password" class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                  <input type="password" id="LAY-user-login-password" name="password" required lay-verify="required" placeholder="密码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">6到16个字符</div>
              </div>
              <div class="layui-form-item">
                <label for="LAY-user-login-repass" class="layui-form-label">确认密码</label>
                <div class="layui-input-inline">
                  <input type="password" id="LAY-user-login-repass" name="repass" required lay-verify="required" placeholder="确认密码" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label for="LAY-user-login-nickname" class="layui-form-label">邮箱</label>
                <div class="layui-input-inline">
                  <input type="text" name="email" id="LAY-user-layui-icon-email" lay-verify="email" placeholder="邮箱" autocomplete="off" class="layui-input">
                </div>
              </div>
              <div class="layui-form-item">
                <label for="LAY-user-login-nickname" class="layui-form-label">手机</label>
                <div class="layui-input-inline">
                  <input type="text" name="phone" id="LAY-user-login-cellphone" lay-verify="phone" placeholder="手机" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">将会成为您唯一找回密码的凭证</div>
              </div>
              <div class="layui-form-item" lay-filter="sex">
                <label class="layui-form-label">选择性别</label>
                <div class="layui-input-block">
                  <input type="radio" name="sex" value="1" title="男" checked>
                  <input type="radio" name="sex" value="0" title="女">
                </div>
              </div>
              <div class="layui-form-item">
                <input type="checkbox" name="agreement" lay-skin="primary" title="同意用户协议" checked>
              </div>
              <div class="layui-form-item">
                <button class="layui-btn" lay-submit lay-filter="LAY-user-reg-submit">立即注册</button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

</div>
<footer th:replace="footer::header-fragment"></footer>

<script src="res/layui/layui.js"></script>
<script>
layui.cache.page = 'user';
layui.cache.user = {
  username: '游客'
  ,uid: -1
  ,avatar: 'res/images/avatar/00.jpg'
  ,experience: 83
  ,sex: '男'
};
layui.config({
  version: "3.0.0"
  ,base: 'res/mods/'
}).extend({
  fly: 'index'
}).use(['fly', 'user'], function(){
  var $ = layui.$
          ,form = layui.form
          ,router = layui.router();
  form.render();
  //提交
  form.on('submit(LAY-user-reg-submit)', function(obj){
    var field = obj.field;
    //确认密码
    if(field.password !== field.repass){
      return layer.msg('两次密码输入不一致');
    }

    //是否同意用户协议
    if(!field.agreement){
      return layer.msg('你必须同意用户协议才能注册');
    }

    //请求接口
    $.post('user/regist',{
      "username":field.username,
      "password":field.password,
      "nickname":field.nickname,
      "phone":field.phone,
      "email":field.email,
      "sex":field.sex
    },function (res){
      if (res.success){
        layer.msg('注册成功', {
          offset: '15px'
          ,icon: 1
          ,time: 1000
        }, function(){
          location.href = 'user'; //跳转到登入页
        });
      }
    },'json');
    return false;
  });

});

</script>

</body>
</html>